<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="Content-Language" content="en">
    <meta name="color-scheme" content="light dark">

    

    <meta name="author" content="SpringHan">
    <meta name="description" content="Emacs 系列
 前言    我是一名 Emacs 用户，我一直不习惯用 magit 的 Commit 操作，原因就是它那频繁的 popup ，我使用的是窗口管理器 dwm ，因此每次在执行 commit 之后都得重新聚焦一下 Emacs 才能再次正常操作。
我的解决方案    恰逢最近看到了个关于 format-commit 的项目，因此便自己写了个函数，函数体如下：
(defun spring/format-commit () &#34;Git commit with formatted text.&#34; (interactive) (let* ((type (completing-read &#34;Enter the commit type: &#34; &#39;(&#34;docs&#34; &#34;file&#34; &#34;modifiy&#34; &#34;feat&#34; &#34;style&#34; &#34;fix&#34;))) (files (read-string (format &#34;Enter the files with %s(use space to split): &#34; type))) content) ;; Commit (setq content (read-string (format &#34;Enter the short content with %s(%s): &#34; type files))) (setq content (concat &#34;\&#34;&#34; type &#34;(&#34; files &#34;): &#34; content &#34;\&#34;&#34;)) (when (= 121 (read-char (format &#34;Content: %s(y/n)&#34; content))) (shell-command (concat &#34;git commit -m &#34; content) &#34; *Format-Commit*&#34;) (kill-buffer &#34; *Format-Commit*&#34;))) (when (eq major-mode &#39;magit-status-mode) (magit-refresh))) 在函数最后与 magit 进行交互，将其刷新，避免了需要手动刷新而导致的间断感。">
    <meta name="keywords" content="developer,emacs">

    <meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="Format Commit - 对Magit的一次改进"/>
<meta name="twitter:description" content="Emacs 系列
 前言    我是一名 Emacs 用户，我一直不习惯用 magit 的 Commit 操作，原因就是它那频繁的 popup ，我使用的是窗口管理器 dwm ，因此每次在执行 commit 之后都得重新聚焦一下 Emacs 才能再次正常操作。
我的解决方案    恰逢最近看到了个关于 format-commit 的项目，因此便自己写了个函数，函数体如下：
(defun spring/format-commit () &#34;Git commit with formatted text.&#34; (interactive) (let* ((type (completing-read &#34;Enter the commit type: &#34; &#39;(&#34;docs&#34; &#34;file&#34; &#34;modifiy&#34; &#34;feat&#34; &#34;style&#34; &#34;fix&#34;))) (files (read-string (format &#34;Enter the files with %s(use space to split): &#34; type))) content) ;; Commit (setq content (read-string (format &#34;Enter the short content with %s(%s): &#34; type files))) (setq content (concat &#34;\&#34;&#34; type &#34;(&#34; files &#34;): &#34; content &#34;\&#34;&#34;)) (when (= 121 (read-char (format &#34;Content: %s(y/n)&#34; content))) (shell-command (concat &#34;git commit -m &#34; content) &#34; *Format-Commit*&#34;) (kill-buffer &#34; *Format-Commit*&#34;))) (when (eq major-mode &#39;magit-status-mode) (magit-refresh))) 在函数最后与 magit 进行交互，将其刷新，避免了需要手动刷新而导致的间断感。"/>

    <meta property="og:title" content="Format Commit - 对Magit的一次改进" />
<meta property="og:description" content="Emacs 系列
 前言    我是一名 Emacs 用户，我一直不习惯用 magit 的 Commit 操作，原因就是它那频繁的 popup ，我使用的是窗口管理器 dwm ，因此每次在执行 commit 之后都得重新聚焦一下 Emacs 才能再次正常操作。
我的解决方案    恰逢最近看到了个关于 format-commit 的项目，因此便自己写了个函数，函数体如下：
(defun spring/format-commit () &#34;Git commit with formatted text.&#34; (interactive) (let* ((type (completing-read &#34;Enter the commit type: &#34; &#39;(&#34;docs&#34; &#34;file&#34; &#34;modifiy&#34; &#34;feat&#34; &#34;style&#34; &#34;fix&#34;))) (files (read-string (format &#34;Enter the files with %s(use space to split): &#34; type))) content) ;; Commit (setq content (read-string (format &#34;Enter the short content with %s(%s): &#34; type files))) (setq content (concat &#34;\&#34;&#34; type &#34;(&#34; files &#34;): &#34; content &#34;\&#34;&#34;)) (when (= 121 (read-char (format &#34;Content: %s(y/n)&#34; content))) (shell-command (concat &#34;git commit -m &#34; content) &#34; *Format-Commit*&#34;) (kill-buffer &#34; *Format-Commit*&#34;))) (when (eq major-mode &#39;magit-status-mode) (magit-refresh))) 在函数最后与 magit 进行交互，将其刷新，避免了需要手动刷新而导致的间断感。" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://springhan.gitee.io/blog/emacs/format-commit/" /><meta property="article:section" content="emacs" />
<meta property="article:published_time" content="2020-11-28T22:07:25&#43;08:00" />
<meta property="article:modified_time" content="2020-11-28T22:07:25&#43;08:00" />



    <title>
  Format Commit - 对Magit的一次改进 · SpringHan Blog
</title>

    
      <link rel="canonical" href="https://springhan.gitee.io/blog/emacs/format-commit/">
    

    <link rel="preload" href="/fonts/forkawesome-webfont.woff2?v=1.1.7" as="font" type="font/woff2" crossorigin>

    
      
      
      <link rel="stylesheet" href="/blog/css/coder.min.04d6bedce375c4fcb6bf1e2c89e70f9e45a3431f1926a9f5f63749517718d366.css" integrity="sha256-BNa&#43;3ON1xPy2vx4siecPnkWjQx8ZJqn19jdJUXcY02Y=" crossorigin="anonymous" media="screen" />
    

    

    
      
        
        
        <link rel="stylesheet" href="/blog/css/coder-dark.min.dde8a61eb31a32353b4baf3d9113f03c4ea2a8ca9bb736f59ca2d2b2cb664f0b.css" integrity="sha256-3eimHrMaMjU7S689kRPwPE6iqMqbtzb1nKLSsstmTws=" crossorigin="anonymous" media="screen" />
      
    

    

    

    <link rel="icon" type="image/png" href="/blog/img/favicon-32x32.png" sizes="32x32">
    <link rel="icon" type="image/png" href="/blog/img/favicon-16x16.png" sizes="16x16">

    <link rel="apple-touch-icon" href="/blog/images/apple-touch-icon.png">
    <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon.png">

    
      <script defer src="https://twemoji.maxcdn.com/v/13.0.2/twemoji.min.js"
        integrity="sha384-wyB/MspSJ/r2bT2kCj44qtsYRYlpzO2oAPhRj5myrWD63dt6qWv4x8AZe7Fl3K3b" crossorigin="anonymous"></script>
    

    <meta name="generator" content="Hugo 0.82.0" />
  </head>

  
  
    
  
  <body class="preload-transitions colorscheme-auto"
        onload=" twemoji.parse(document.body); "
  >
    
<div class="float-container">
    <a id="dark-mode-toggle" class="colorscheme-toggle">
        <i class="fa fa-adjust fa-fw" aria-hidden="true"></i>
    </a>
</div>


    <main class="wrapper">
      <nav class="navigation">
  <section class="container">
    <a class="navigation-title" href="/blog">
      SpringHan Blog
    </a>
    
      <input type="checkbox" id="menu-toggle" />
      <label class="menu-button float-right" for="menu-toggle">
        <i class="fa fa-bars fa-fw" aria-hidden="true"></i>
      </label>
      <ul class="navigation-list">
        
          
            <li class="navigation-item">
              <a class="navigation-link" href="/blog/emacs/">Emacs</a>
            </li>
          
        
        
      </ul>
    
  </section>
</nav>


      <div class="content">
        
  <section class="container page">
  <article>
    <header>
      <h1 class="title">
        <a class="title-link" href="https://springhan.gitee.io/blog/emacs/format-commit/">
          Format Commit - 对Magit的一次改进
        </a>
      </h1>
    </header>

    <blockquote>
<p>Emacs 系列</p>
</blockquote>
<h3 id="前言">
  前言
  <a class="heading-link" href="#%e5%89%8d%e8%a8%80">
    <i class="fa fa-link" aria-hidden="true"></i>
  </a>
</h3>
<p>我是一名 Emacs 用户，我一直不习惯用 <code>magit</code> 的 Commit 操作，原因就是它那频繁的 <code>popup</code> ，我使用的是窗口管理器 <code>dwm</code> ，因此每次在执行 commit 之后都得重新聚焦一下 Emacs 才能再次正常操作。</p>
<h3 id="我的解决方案">
  我的解决方案
  <a class="heading-link" href="#%e6%88%91%e7%9a%84%e8%a7%a3%e5%86%b3%e6%96%b9%e6%a1%88">
    <i class="fa fa-link" aria-hidden="true"></i>
  </a>
</h3>
<p>恰逢最近看到了个关于 <code>format-commit</code> 的项目，因此便自己写了个函数，函数体如下：</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-emacs-lisp" data-lang="emacs-lisp">(defun spring/format-commit ()
  <span style="color:#e6db74">&#34;Git commit with formatted text.&#34;</span>
  (interactive)
  (let* ((type (<span style="color:#a6e22e">completing-read</span> <span style="color:#e6db74">&#34;Enter the commit type: &#34;</span>
                                <span style="color:#f92672">&#39;</span>(<span style="color:#e6db74">&#34;docs&#34;</span> <span style="color:#e6db74">&#34;file&#34;</span> <span style="color:#e6db74">&#34;modifiy&#34;</span> <span style="color:#e6db74">&#34;feat&#34;</span> <span style="color:#e6db74">&#34;style&#34;</span> <span style="color:#e6db74">&#34;fix&#34;</span>)))
         (files (<span style="color:#a6e22e">read-string</span> (<span style="color:#a6e22e">format</span>
                              <span style="color:#e6db74">&#34;Enter the files with %s(use space to split): &#34;</span>
                              type)))
         content)
    <span style="color:#75715e">;; Commit</span>
    (setq content (<span style="color:#a6e22e">read-string</span> (<span style="color:#a6e22e">format</span>
                                <span style="color:#e6db74">&#34;Enter the short content with %s(%s): &#34;</span>
                                type files)))
    (setq content (<span style="color:#a6e22e">concat</span> <span style="color:#e6db74">&#34;\&#34;&#34;</span> type <span style="color:#e6db74">&#34;(&#34;</span> files <span style="color:#e6db74">&#34;): &#34;</span> content <span style="color:#e6db74">&#34;\&#34;&#34;</span>))
    (when (<span style="color:#a6e22e">=</span> <span style="color:#ae81ff">121</span> (<span style="color:#a6e22e">read-char</span> (<span style="color:#a6e22e">format</span> <span style="color:#e6db74">&#34;Content: %s(y/n)&#34;</span> content)))
      (shell-command (<span style="color:#a6e22e">concat</span> <span style="color:#e6db74">&#34;git commit -m &#34;</span> content) <span style="color:#e6db74">&#34; *Format-Commit*&#34;</span>)
      (<span style="color:#a6e22e">kill-buffer</span> <span style="color:#e6db74">&#34; *Format-Commit*&#34;</span>)))
  (when (<span style="color:#a6e22e">eq</span> major-mode <span style="color:#e6db74">&#39;magit-status-mode</span>)
    (magit-refresh)))
</code></pre></div><p>在函数最后与 <code>magit</code> 进行交互，将其刷新，避免了需要手动刷新而导致的间断感。<br>
并在 <code>magit</code> 配置中将 <code>(magit-commit)</code> 重新定义，不影响原来的操作。(这里还发现 <code>magit</code> 用的是 <code>(transient-define-prefix)</code>)</p>
<p>总之，目前 <code>magit</code> 的使用体验还可以。</p>

  </article>
</section>

  

      </div>

      
  <footer class="footer">
    <section class="container">
      
      
        ©
        
          2019 -
        
        2021
         SpringHan 
      
      
         · 
        Powered by <a href="https://gohugo.io/">Hugo</a> & SpringHan.
      
      
    </section>
  </footer>


    </main>

    
      
      <script src="/blog/js/coder.min.235666b114443867d43eeb5799d51f6252965e5163f338285e113fa381d3d27e.js" integrity="sha256-I1ZmsRREOGfUPutXmdUfYlKWXlFj8zgoXhE/o4HT0n4="></script>
    

    

    

    

    

    

    

    

    
  </body>

</html>
